<?php
/**
 * Created by PhpStorm.
 * User: moquan
 * Date: 2019/3/12
 * Time: 20:39
 */

namespace app\admin\model;


class AdminUser extends BaseModel {
    protected function setPasswordAttr( $value ) {
        return md5($value);
    }

    function role(){
        return $this->belongsTo('AdminRole','role_id', 'role_id');
    }

    static function getAdminUserById( $id ) {
        return self::with('role')->where( 'admin_id', $id )->find();
    }

    static function getAdminUserByUserPwd( $where ) {
        dump($where);
        $res = self::with('role')->where( $where )->find();
        return $res;
    }

    public static function getAdminUserList() {
        $list = self::with('role')->field("*, if(status=1,'开启','禁用') as status_name")->order('role_id desc')->paginate();
        return $list->hidden(['password', 'role' => ['desc']]);
    }

    public static function delUserByID( $id ) {
        return self::where( 'admin_id', $id )->delete();
    }
}